using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using System.Windows.Forms;
namespace HostpitalDevice.Business
{
     public class login
    {
        public static Boolean validate(String name, String password)
        {
           String  sql = string.Format("select id from login where name='{0}' and password ='{1}'", name,password);
           OleDbDataReader reader =DBHelper.ExecuteDataReader(sql);
           if (reader.HasRows)
           {
               return true;
           }
           else
           {
               return false;
           }
        }

        public static bool IsExists(string name)
        {
            String sql = string.Format("select id from login where name='{0}'", name);
            OleDbDataReader reader = DBHelper.ExecuteDataReader(sql);
            if (reader.HasRows)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static Boolean updateUserInfo(String oName,String oPassword,String nName,String nPassword)
        {

            String sql = string.Format("update login set [name]='{0}',[password]='{1}'where [name]='{2}' and [password]='{3}'", nName,nPassword,oName,oPassword);
                if (DBHelper.ExecuteUpdate(sql) > 0)
                {
                    return true;
                }
                else
                    return false; 
        }

        public static bool newUserInfo(string nName, string nPassword)
        {
            string sql = string.Format("insert into login(name,[password]) values('{0}','{1}')", nName, nPassword);
            Helper hp = new Helper();
            try
            {
                hp.ExecuteSql(sql);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
    }
}
